/**
 * 时间戳转日期：年-月-日 时:分
 * @param timestamp
 */
export function timestampToDate(timestamp1: string): string {
    let timestamp = ''
    if (String(Math.floor(Number(timestamp1))).length > 10) {
        timestamp = String(Number(timestamp1) / 1000)
    } else {
        timestamp = timestamp1
    }
    const date = new Date(Number(timestamp) * 1000);
    const year = date.getFullYear();
    const month = (date.getMonth() + 1).toString().padStart(2, '0');
    const day = date.getDate().toString().padStart(2, '0');
    const hours = date.getHours().toString().padStart(2, '0');
    const minutes = date.getMinutes().toString().padStart(2, '0');

    console.log(Math.floor(Number(timestamp)))
    return `${year}-${month}-${day} ${hours}:${minutes}`;
}

/**
 * 日期转时间戳
 * @param date
 * @constructor
 */
export function DateToTimestamp(date: any): number {
    // 如果传入的日期是字符串，尝试将其解析为Date对象
    if (typeof date === 'string') {
        date = new Date(date);
    }

    // 如果传入的日期是有效的Date对象，返回时间戳
    if (date instanceof Date && !isNaN(date.getTime())) {
        return date.getTime() / 1000;
    }

    // 如果传入的日期无效，抛出错误
    throw new Error('Invalid date value');
}

/**
 * 从时间戳获取星期几
 * @param timestamp - 时间戳（毫秒）
 * @returns 星期几的字符串表示
 */
export function getWeekdayFromTimestamp(timestamp: string): string {
    const date = new Date(Number(timestamp) * 1000);
    const daysOfWeek = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    return daysOfWeek[date.getDay()];
}